package com.cyandpos.pad.offline.upload;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.utils.MoneyUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 20211109
 * 上传失败adapter
 */
public class OfflineUploadFailAdapter extends BaseAdapter {

    private Context mContext;
    private List<TicketOffline> mData;//刷了几张卡的列表

    public OfflineUploadFailAdapter(Context context, List<TicketOffline> data ) {
        this.mContext = context;
        this.mData = data;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public TicketOffline getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder ;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_offline_upload_fail, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvOrderno.setText(getItem(position).getOrderNo());
        holder.tvSaleMoney.setText(MoneyUtils.getMoneyStr(getItem(position).getSaleMoney()));
        holder.tvKssj.setText(getItem(position).getKssj());
//        if (position % 2 == 0) {
//            convertView.setBackgroundResource(R.mipmap.yhq_even);
//        } else {
//            convertView.setBackgroundResource(R.mipmap.yhq_odd);
//        }
        return convertView;
    }

    public static class ViewHolder {
        @BindView(R.id.tv_upload_fail_orderno)
        TextView tvOrderno;
        @BindView(R.id.tv_upload_fail_saleMoney)
        TextView tvSaleMoney;
        @BindView(R.id.tv_upload_fail_kssj)
        TextView tvKssj;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
